﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tomato.Serialization;
using System.IO;

namespace System
{
    public static class ObjectExtension
    {
        public static string ToJson(this object obj)
        {
            return new JsonSerializer().Serialize(obj);
        }

        public static string ToJsonBase64(this object obj)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                new JsonSerializer().Serialize(stream, obj);
                return Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length);
            }
        }
    }
}
